package ecode

import (
	"geak/libs/ecode"
	"strconv"
)

func (e *Error) Error() string {
	return strconv.FormatInt(int64(e.GetErrCode()), 10)
}
// Code is the code of error.
func (e *Error) Code() int {
	return int(e.GetErrCode())
}

// Message is error message.
func (e *Error) Message() string {
	return e.GetErrMsg()
}

// Equal compare whether two errors are equal.
func (e *Error) Equal(ec error) bool {
	return ecode.Cause(ec).Code() == e.Code()
}

// Details return error details.
func (e *Error) Details() []interface{} { return nil }

// From will convert ecode.Codes to pb.Error.
func From(ec ecode.Codes) *Error {
	return &Error{
		ErrCode:    int64(ec.Code()),
		ErrMsg: 	ec.Message(),
	}
}